import {
  HTTP
} from '../utils/http.js';

class CommentModel extends HTTP {

  /**
   * 根据内容ID查询评论
   * @param {Long} contentId 
   * @param {Integer} pageNum 
   * @param {Integer} pageSize 
   */
  getCommentsByContentId(contentId, pageNum, pageSize = 50) {
    return this.request({
      url: "commentIndex/findByContentId",
      data: {
        "token": wx.getStorageSync('token'),
        "contentId": contentId,
        "pageNum": pageNum,
        "pageSize": pageSize
      },
      method: 'POST'
    })
  }

  /**
   * 评论操作
   * @param {Object} param 参数
   * @param {String} type 操作类型
   */
  operate(param, type = 'add') {
    return this.request({
      url: `comment/${type === 'add' ? 'add' : 'reply'}`,
      data: {
        'token': wx.getStorageSync('token'),
        'comment': JSON.stringify(param)
      },
      method: 'POST'
    })
  }

  /**
   * 查看详情信息
   * @param {Long} commentId 
   */
  findCommentDetail(commentId) {
    return this.request({
      url: 'commentIndex/findCommentDetail',
      data: {
        "token": wx.getStorageSync('token'),
        'commentId': commentId
      },
      method: 'POST'
    })
  }

  /**
   * 查看回复详情子集
   * @param {Long} commentId 
   */
  findCommentDetailChildren(commentId, pageNum, pageSize = 50) {
    return this.request({
      url: 'commentIndex/findCommentDetailChildren',
      data: {
        "token": wx.getStorageSync('token'),
        'commentId': commentId,
        "pageNum": pageNum,
        "pageSize": pageSize
      },
      method: 'POST'
    })
  }

  /**
   * 评论点赞
   * @param {Long} commentId 
   */
  like(commentId) {
    return this.request({
      url: 'comment/like',
      data: {
        'token': wx.getStorageSync('token'),
        'commentId': commentId
      },
      method: 'POST'
    })
  }

  /**
   * 取消评论点赞
   * @param {Long} commentId 
   */
  unlike(commentId) {
    return this.request({
      url: 'comment/unlike',
      data: {
        'token': wx.getStorageSync('token'),
        'commentId': commentId
      },
      method: 'POST'
    })
  }

  /**
   * 删除评论
   * @param {Long} contentId 
   * @param {Long} commentId 
   */
  delete(contentId, commentId) {
    return this.request({
      url: 'comment/delete',
      data: {
        'contentId': contentId,
        'commentId': commentId
      },
      method: 'POST'
    })
  }

}

export {
  CommentModel
}